using System;
using System.Windows;

namespace FluentSilverlight.Expressions.TextItems
{

    public class ValueDependencyObject : DependencyObject, IValueDependencyObject
    {
        public event EventHandler<ViewValueChangedEventArgs> ViewValueChanged;

        public static readonly DependencyProperty ValueProperty =
            DependencyProperty.Register("Value", typeof(object), typeof(ValueDependencyObject),
                                        new PropertyMetadata(OnValueChangedStatic));

        private static void OnValueChangedStatic(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((ValueDependencyObject)d).OnValueChanged(e.NewValue);
        }

        private void OnValueChanged(object value)
        {
            if (ViewValueChanged != null)
                ViewValueChanged(this, new ViewValueChangedEventArgs(value));
        }

        public void SetValue(object value)
        {
            SetValue(ValueProperty, value);
        }

        public object GetValue()
        {
            return GetValue(ValueProperty);
        }
    }
}